<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // const ajax=function(){

        // }
        const ajax = (url) => {
            return new Promise((resolve, reject) => {
                console.log(url);
                let xhr=new XMLHttpRequest()
                xhr.open('GET',url)
                // xhr.send()
                xhr.onreadystatechange=()=>{
                    if(xhr.readyState==4&&xhr.status==200)
                    console.log(2);
                    console.log(xhr.responseText,'msg');
                    resolve(xhr.responseText)
                    
                }
                xhr.send();
            })
        }
        
        ajax('http://127.0.0.1:3000/test')
        .then(res=>{
            console.log(res,'msg');
        })


        // const xml =(url)=>{
        //     return new  Promise((resolve,reject)=>{
        //         let xml=new XMLHttpRequest()
        //         xml.open('GET',url)
        //         xml.onreadystatechange=()=>{
        //             if(xml.readyState==4&xml.status==200){
        //                 resolve(xml.responseText)
        //             }
        //         }
        //         xml.send()
                
        //     })
        // }
    </script>
</body>

</html>